package com.chis.sms.smsServer;

/**
 * @Description webservice接口
 * @Company zwx
 * @author jw
 * @version 2018年8月14日
 */
public class SmsServerProxy implements SmsServer {
	/**端点*/
	private String _endpoint = null;
	/**服务*/
	private SmsServer smsServer = null;

	public SmsServerProxy() {
		_initSmsServerProxy();
	}

	public SmsServerProxy(String endpoint) {
		_endpoint = endpoint;
		_initSmsServerProxy();
	}

	/**
	 * 初始化服务
	 */
	private void _initSmsServerProxy() {
		try {
			smsServer = (new SmsServiceLocator()).getSmsServerPort();
			if (smsServer != null) {
				if (_endpoint != null)
					((javax.xml.rpc.Stub) smsServer)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
				else
					_endpoint = (String) ((javax.xml.rpc.Stub) smsServer)._getProperty("javax.xml.rpc.service.endpoint.address");
			}

		} catch (javax.xml.rpc.ServiceException serviceException) {
		}
	}

	public String getEndpoint() {
		return _endpoint;
	}

	/**
	 * 设置代理
	 * @param endpoint 端点
	 */
	public void setEndpoint(String endpoint) {
		_endpoint = endpoint;
		if (smsServer != null)
			((javax.xml.rpc.Stub) smsServer)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);

	}

	/**
	 * 获取服务
	 * @return 服务
	 */
	public SmsServer getSmsServer() {
		if (smsServer == null)
			_initSmsServerProxy();
		return smsServer;
	}

	/**
	 * 上传短信信息
	 * @param upString 短信压缩串，需进行GZIP解压缩
	 * @param userCode 用户名
	 * @param passWord 密码
	 * @return 0：成功 ，-1：失败
	 * @throws java.rmi.RemoteException 异常
	 */
	public int smsUpLoad(String upString, String userCode, String passWord) throws java.rmi.RemoteException {
		if (smsServer == null)
			_initSmsServerProxy();
		return smsServer.smsUpLoad(upString, userCode, passWord);
	}

}